package com.chen.demo.netty.base.buffer;

import java.nio.ByteBuffer;

/**
 * buffer内存分配策略
 * 1：堆上分配
 * 2：直接内存分配
 *
 * @author chenhongwei
 * @date 2020/3/20 20:13
 **/
public class AllocateBuffer {

    public static void main(String[] args) {
        System.out.println("before allocate:" + Runtime.getRuntime().freeMemory());
   /*     ByteBuffer byteBuffer = ByteBuffer.allocate(102400000);
        //堆内存分配
        System.out.println("ByteBuffer :" + byteBuffer);
        System.out.println("after allocate:" + Runtime.getRuntime().freeMemory());*/
        //直接内存分配

        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024000);
        System.out.println("ByteBuffer :" + byteBuffer);
        System.out.println("direct allocate:" + Runtime.getRuntime().freeMemory());

    }
}
